package tgc.edu.ljc.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import org.springframework.data.annotation.CreatedBy;

import com.fasterxml.jackson.annotation.JsonIgnore;

import tgc.edu.ljc.custom.BaseEntity;

/***
 * 数据字典
 * 
 * @author zmq
 *
 */

@Entity
public class DataSum extends BaseEntity<Integer> {
	private String name;
	private String code;
	@JsonIgnore
	private DataSum parent;
	@JsonIgnore
	private List<DataSum> children = new ArrayList<>();

	@Column(length = 20)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@ManyToOne
	@CreatedBy
	public DataSum getParent() {
		return parent;
	}

	public void setParent(DataSum parent) {
		this.parent = parent;
	}

	@OneToMany(cascade = CascadeType.ALL, mappedBy = "parent")
	public List<DataSum> getChildren() {
		return children;
	}

	public void setChildren(List<DataSum> children) {
		this.children = children;
	}
	public DataSum() {
		super();
	}
	public DataSum(Integer id) {
		super(id);
	}

	@Transient
	public Integer getParentId() {
		return parent == null ? null : parent.getId();
	}

}
